package com.iloooo.kaptchademo;

import com.google.code.kaptcha.servlet.KaptchaServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebmvcConfiguration implements WebMvcConfigurer {

    @Bean
    public ServletRegistrationBean registerServlet() {
        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(
                new KaptchaServlet(), "/Kaptcha.jpg");
        servletRegistrationBean.addInitParameter("kaptcha.border","no");
        servletRegistrationBean.addInitParameter("kaptcha.textproducer.font.color","68,146,195");
        servletRegistrationBean.addInitParameter("kaptcha.textproducer.char.length","4");
        servletRegistrationBean.addInitParameter("kaptcha.noise.impl","com.google.code.kaptcha.impl.NoNoise");
        servletRegistrationBean.addInitParameter("kaptcha.textproducer.char.space","8");
        servletRegistrationBean.addInitParameter("kaptcha.textproducer.font.size","40");
        servletRegistrationBean.addInitParameter("kaptcha.image.height","50");
        servletRegistrationBean.addInitParameter("kaptcha.image.width","150");
        servletRegistrationBean.addInitParameter("kaptcha.textproducer.char.string","123456789abcdefghijklmnpqrstuvwxyz");
        servletRegistrationBean.addInitParameter("kaptcha.textproducer.font.names","Arial");
        servletRegistrationBean.addInitParameter("kaptcha.obscurificator.impl","com.google.code.kaptcha.impl.WaterRipple");
        return servletRegistrationBean;
    }

    /*@Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(new StringToLocalDate());
        registry.addConverter(new StringToLocalDateTime());
        registry.addConverter(new StringToDate());
    }*/


}